AC_INIT(emc, 0.0.1, dave@gurumeditation.it)
AC_PREREQ([2.60])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
AC_GNU_SOURCE
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_ISC_POSIX

AM_INIT_AUTOMAKE(1.6 dist-bzip2)
AM_CONFIG_HEADER(config.h)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])
define([AC_LIBTOOL_LANG_GCJ_CONFIG], [:])
define([AC_LIBTOOL_LANG_F77_CONFIG], [:])
AC_PROG_LIBTOOL

VMAJ=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $1);}'`
VMIN=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $2);}'`
VMIC=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $3);}'`
SNAP=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $4);}'`
version_info=`expr $VMAJ + $VMIN`":$VMIC:$VMIN"
AC_SUBST(VMAJ)
AC_SUBST(version_info)

AC_C_BIGENDIAN
AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_C_CONST
AC_FUNC_ALLOCA
AC_C___ATTRIBUTE__

ALL_LINGUAS=`cat po/LINGUAS | grep -v '^[ ]*#'`
AC_SUBST(ALL_LINGUAS)

AM_GNU_GETTEXT_VERSION([0.12.1])
AM_GNU_GETTEXT([external])

##################
# Mandatory Libs #
##################
PKG_CHECK_MODULES([ELEMENTARY], [elementary >= 0.5.1.0])
PKG_CHECK_MODULES([EFREET], [efreet >= 0.5.0.062])
PKG_CHECK_MODULES([EMOTION], [emotion >= 0.1.0.042])
#~ PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
#~ PKG_CHECK_MODULES([LIBCURL], [libcurl])


##################
# Optional Libs  #
##################
#AC_E_CHECK_PKG([LIBXML2], [libxml-2.0])
#AM_CONDITIONAL(BUILD_LIBXML2, test BUILD_LIBXML2)


##################
# Edje cc        #
##################
AC_ARG_WITH([edje-cc],
   [AC_HELP_STRING([--with-edje-cc=PATH],
                   [specify a specific path to edje_cc])],
   [edje_cc=$withval;
    AC_MSG_NOTICE([edje_cc explicitly set to $edje_cc])
   ],[edje_cc=$(pkg-config --variable=prefix edje)/bin/edje_cc])
AC_SUBST(edje_cc)


##################
# Quicklaunch    #
##################
enable_quicklaunch="auto"
AC_ARG_ENABLE([quicklaunch],
   [AC_HELP_STRING([--disable-quicklaunch],
                   [disable build of quicklaunch (default=auto)])],
   [if test "x${enableval}" = "xno"; then
       enable_quicklaunch="no"
    elif test "x${enableval}" = "xyes"; then
       enable_quicklaunch="yes"
    else
       enable_quicklaunch="auto"
    fi
   ],
   [enable_quicklaunch="auto"])

if test "x${enable_quicklaunch}" = "xauto"; then
   AC_MSG_CHECKING([checking for elementary_quicklaunch binary...])
   if test -x $(pkg-config --variable=prefix elementary)/bin/elementary_quicklaunch; then
      AC_MSG_RESULT([found, enable quicklaunch.])
      enable_quicklaunch="yes"
   else
      AC_MSG_RESULT([not found, disable quicklaunch.])
      enable_quicklaunch="no"
   fi
fi

if test "x${enable_quicklaunch}" = "xyes"; then
   AC_ARG_WITH([quicklauncher-libdir],
      [AC_HELP_STRING([--with-quicklauncher-libdir=PATH],
                      [specify a specific path to install quicklauncher binaries])],
      [quicklauncher_libdir=$withval;
      AC_MSG_NOTICE([quicklauncher_libdir explicitly set to $quicklauncher_libdir])
      ],
      [quicklauncher_libdir=$(pkg-config --variable=libdir elementary)])
   AC_SUBST(quicklauncher_libdir)
fi

AM_CONDITIONAL(BUILD_QUICKLAUNCH, test "x${enable_quicklaunch}" = "xyes")


#################
# Input Modules #
#################

# LIRC
AM_CONDITIONAL(HAVE_LIRC, false) #needed?
define([CHECK_MODULE_LIRC],
[
   AC_CHECK_HEADER(lirc/lirc_client.h, [], LIRC=false)
])
AC_E_OPTIONAL_MODULE([lirc], true, [CHECK_MODULE_LIRC])

# JOYSTICK
AM_CONDITIONAL(HAVE_JOYSTICK, false) #needed?
define([CHECK_MODULE_JOYSTICK],
[
   AC_CHECK_HEADER(linux/joystick.h, [], JOYSTICK=false)
])
AC_E_OPTIONAL_MODULE([joystick], true, [CHECK_MODULE_JOYSTICK])


# KEYB
AC_E_OPTIONAL_MODULE([keyb], true)

####################
# Modules          #
####################
AC_E_OPTIONAL_MODULE([film], true)
AC_E_OPTIONAL_MODULE([tvshow], true)
AC_E_OPTIONAL_MODULE([mame], true)
AC_E_OPTIONAL_MODULE([sysgames], true)



##################
# Automake       #
##################
AC_OUTPUT([
Makefile
src/Makefile
src/bin/Makefile
src/modules/Makefile
src/modules/input/Makefile
src/modules/input/keyb/Makefile
src/modules/input/lirc/Makefile
src/modules/input/joy/Makefile
src/modules/videos/Makefile
src/modules/videos/film/Makefile
src/modules/videos/tvshow/Makefile
src/modules/games/Makefile
src/modules/games/mame/Makefile
src/modules/games/sysgames/Makefile
data/Makefile
data/desktop/Makefile
data/themes/Makefile
data/themes/default/Makefile
po/Makefile.in
])


##################
# Final Report   #
##################
cat << EOF

$PACKAGE $VERSION configured with:

Flags:
   CFLAGS.....(C): $CFLAGS
   CXXFLAGS.(C++): $CXXFLAGS
   CPPFLAGS.(CPP): $CPPFLAGS
   LDFLAGS...(LD): $LDFLAGS

Installation Path:.......: $prefix
   Binaries..............: $prefix/bin
   Modules...............: $prefix/lib/emc/modules
   Themes................: $prefix/share/emc/themes

Quick Launcher:..........: ${enable_quicklaunch}
   quicklauncher_libdir..: $quicklauncher_libdir


Enabled modules..........:$OPTIONAL_MODULES
Disabled modules.........:$UNUSED_OPTIONAL_MODULES


Now type 'make' ('gmake' on some systems) to compile emc, if it
builds successfully then you can 'make install', acquiring required
permissions with 'su' or 'sudo'.

EOF

